package com.gcxy.exception.handler;

import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import com.gcxy.core.R;
import com.gcxy.enums.ResultCodeEnum;
import com.gcxy.exception.annotation.GlobalException;
import com.gcxy.exception.global.IGlobalException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Copyright (C), 2024-2024, BUG闭退！
 * Author: Huang先森
 * Date: 2024/7/22 13:33
 * FileName: MismatchedInputExceptionHandler
 * Description: * 不匹配的输入异常
 */
@GlobalException(throwable = MismatchedInputException.class)
public class MismatchedInputExceptionHandler implements IGlobalException<R, MismatchedInputException> {

    @Override
    public R exception(MismatchedInputException throwable, HttpServletRequest request, HttpServletResponse response) {
        return BaseThrowExceptionHandler.exception(throwable, ResultCodeEnum.REQUEST_PARAM_ERROR, () ->
                String.format("请求参数类型:%s与实际请求参数类型不匹配", throwable.getTargetType().getSimpleName())
        );
    }
}
